{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "755017d1-986d-47fe-81ae-d062ff28ecf9",
   "metadata": {
    "tags": []
   },
   "source": [
    "> 「页面」funasr  https://www.funasr.com/#/\n",
    "\n",
    "> 「页面」FunASR/README_zh.mdat main · modelscope/FunASR  https://github.com/modelscope/FunASR/blob/main/README_zh.md#%E6%A8%A1%E5%9E%8B%E4%BB%93%E5%BA%93\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "094fbc0f-7c51-452e-94de-10218650a13e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-09-24T07:16:55.040768Z",
     "iopub.status.busy": "2024-09-24T07:16:55.040438Z",
     "iopub.status.idle": "2024-09-24T07:16:58.955478Z",
     "shell.execute_reply": "2024-09-24T07:16:58.954841Z",
     "shell.execute_reply.started": "2024-09-24T07:16:55.040749Z"
    },
    "tags": []
   },
   "source": [
    "!pip install pydub"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "50819c5a-f2b2-41c9-b870-09ad163e7a3f",
   "metadata": {
    "ExecutionIndicator": {
     "show": true
    },
    "execution": {
     "iopub.execute_input": "2024-09-24T07:18:46.899845Z",
     "iopub.status.busy": "2024-09-24T07:18:46.899521Z",
     "iopub.status.idle": "2024-09-24T07:18:47.360081Z",
     "shell.execute_reply": "2024-09-24T07:18:47.359644Z",
     "shell.execute_reply.started": "2024-09-24T07:18:46.899826Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<_io.BufferedRandom name='/mnt/workspace/notebook_hub_ms/demo/right_channel.mp3'>"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pydub import AudioSegment\n",
    "\n",
    "def split_channels(mp3_file):\n",
    "    sound = AudioSegment.from_mp3(mp3_file)\n",
    "    left_channel = sound.split_to_mono()[0]\n",
    "    right_channel = sound.split_to_mono()[1]\n",
    "    return left_channel, right_channel\n",
    "\n",
    "mp3_filename = \"/mnt/workspace/notebook_hub_ms/demo/demo4.mp3\"\n",
    "left, right = split_channels(mp3_filename)\n",
    "\n",
    "# 保存左声道为新的 MP3 文件\n",
    "left.export(\"/mnt/workspace/notebook_hub_ms/demo/left_channel.mp3\", format=\"mp3\")\n",
    "\n",
    "# 保存右声道为新的 MP3 文件\n",
    "right.export(\"/mnt/workspace/notebook_hub_ms/demo/right_channel.mp3\", format=\"mp3\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4e2e86d0-bbcc-44a0-9cff-fd0ba2b7e78e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-09-25T01:14:53.566820Z",
     "iopub.status.busy": "2024-09-25T01:14:53.566516Z",
     "iopub.status.idle": "2024-09-25T01:15:02.143780Z",
     "shell.execute_reply": "2024-09-25T01:15:02.143201Z",
     "shell.execute_reply.started": "2024-09-25T01:14:53.566801Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://mirrors.cloud.aliyuncs.com/pypi/simple\n",
      "Requirement already satisfied: funasr in /usr/local/lib/python3.10/site-packages (1.1.6)\n",
      "Requirement already satisfied: modelscope in /usr/local/lib/python3.10/site-packages (1.18.0)\n",
      "Collecting modelscope\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/7e/dc/7f0bb60011f0b62ffb373066ad3022cd91db813068fc245ab081a2a4aa40/modelscope-1.18.1-py3-none-any.whl (5.7 MB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m5.7/5.7 MB\u001b[0m \u001b[31m54.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
      "\u001b[?25hRequirement already satisfied: kaldiio>=2.17.0 in /usr/local/lib/python3.10/site-packages (from funasr) (2.18.0)\n",
      "Requirement already satisfied: scipy>=1.4.1 in /usr/local/lib/python3.10/site-packages (from funasr) (1.12.0)\n",
      "Requirement already satisfied: editdistance>=0.5.2 in /usr/local/lib/python3.10/site-packages (from funasr) (0.5.2)\n",
      "Requirement already satisfied: hydra-core>=1.3.2 in /usr/local/lib/python3.10/site-packages (from funasr) (1.3.2)\n",
      "Requirement already satisfied: umap-learn in /usr/local/lib/python3.10/site-packages (from funasr) (0.5.6)\n",
      "Requirement already satisfied: jaconv in /usr/local/lib/python3.10/site-packages (from funasr) (0.4.0)\n",
      "Requirement already satisfied: jieba in /usr/local/lib/python3.10/site-packages (from funasr) (0.42.1)\n",
      "Requirement already satisfied: torch-complex in /usr/local/lib/python3.10/site-packages (from funasr) (0.4.4)\n",
      "Requirement already satisfied: oss2 in /usr/local/lib/python3.10/site-packages (from funasr) (2.18.6)\n",
      "Requirement already satisfied: librosa in /usr/local/lib/python3.10/site-packages (from funasr) (0.10.2.post1)\n",
      "Requirement already satisfied: sentencepiece in /usr/local/lib/python3.10/site-packages (from funasr) (0.2.0)\n",
      "Requirement already satisfied: requests in /usr/local/lib/python3.10/site-packages (from funasr) (2.32.3)\n",
      "Requirement already satisfied: pytorch-wpe in /usr/local/lib/python3.10/site-packages (from funasr) (0.0.1)\n",
      "Requirement already satisfied: tqdm in /usr/local/lib/python3.10/site-packages (from funasr) (4.66.4)\n",
      "Requirement already satisfied: soundfile>=0.12.1 in /usr/local/lib/python3.10/site-packages (from funasr) (0.12.1)\n",
      "Requirement already satisfied: PyYAML>=5.1.2 in /usr/local/lib/python3.10/site-packages (from funasr) (6.0.1)\n",
      "Requirement already satisfied: jamo in /usr/local/lib/python3.10/site-packages (from funasr) (0.4.1)\n",
      "Requirement already satisfied: tensorboardX in /usr/local/lib/python3.10/site-packages (from funasr) (2.6.2.2)\n",
      "Requirement already satisfied: urllib3>=1.26 in /usr/local/lib/python3.10/site-packages (from modelscope) (2.2.1)\n",
      "Requirement already satisfied: packaging in /usr/local/lib/python3.10/site-packages (from hydra-core>=1.3.2->funasr) (24.0)\n",
      "Requirement already satisfied: antlr4-python3-runtime==4.9.* in /usr/local/lib/python3.10/site-packages (from hydra-core>=1.3.2->funasr) (4.9.3)\n",
      "Requirement already satisfied: omegaconf<2.4,>=2.2 in /usr/local/lib/python3.10/site-packages (from hydra-core>=1.3.2->funasr) (2.3.0)\n",
      "Requirement already satisfied: numpy in /usr/local/lib/python3.10/site-packages (from kaldiio>=2.17.0->funasr) (1.26.4)\n",
      "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/site-packages (from requests->funasr) (3.7)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/site-packages (from requests->funasr) (3.3.2)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/site-packages (from requests->funasr) (2024.2.2)\n",
      "Requirement already satisfied: cffi>=1.0 in /usr/local/lib/python3.10/site-packages (from soundfile>=0.12.1->funasr) (1.16.0)\n",
      "Requirement already satisfied: audioread>=2.1.9 in /usr/local/lib/python3.10/site-packages (from librosa->funasr) (3.0.1)\n",
      "Requirement already satisfied: lazy-loader>=0.1 in /usr/local/lib/python3.10/site-packages (from librosa->funasr) (0.4)\n",
      "Requirement already satisfied: typing-extensions>=4.1.1 in /usr/local/lib/python3.10/site-packages (from librosa->funasr) (4.12.0)\n",
      "Requirement already satisfied: msgpack>=1.0 in /usr/local/lib/python3.10/site-packages (from librosa->funasr) (1.0.8)\n",
      "Requirement already satisfied: soxr>=0.3.2 in /usr/local/lib/python3.10/site-packages (from librosa->funasr) (0.4.0)\n",
      "Requirement already satisfied: joblib>=0.14 in /usr/local/lib/python3.10/site-packages (from librosa->funasr) (1.4.2)\n",
      "Requirement already satisfied: numba>=0.51.0 in /usr/local/lib/python3.10/site-packages (from librosa->funasr) (0.60.0)\n",
      "Requirement already satisfied: pooch>=1.1 in /usr/local/lib/python3.10/site-packages (from librosa->funasr) (1.8.2)\n",
      "Requirement already satisfied: decorator>=4.3.0 in /usr/local/lib/python3.10/site-packages (from librosa->funasr) (4.4.2)\n",
      "Requirement already satisfied: scikit-learn>=0.20.0 in /usr/local/lib/python3.10/site-packages (from librosa->funasr) (1.5.0)\n",
      "Requirement already satisfied: aliyun-python-sdk-core>=2.13.12 in /usr/local/lib/python3.10/site-packages (from oss2->funasr) (2.15.1)\n",
      "Requirement already satisfied: pycryptodome>=3.4.7 in /usr/local/lib/python3.10/site-packages (from oss2->funasr) (3.20.0)\n",
      "Requirement already satisfied: crcmod>=1.7 in /usr/local/lib/python3.10/site-packages (from oss2->funasr) (1.7)\n",
      "Requirement already satisfied: aliyun-python-sdk-kms>=2.4.1 in /usr/local/lib/python3.10/site-packages (from oss2->funasr) (2.16.3)\n",
      "Requirement already satisfied: six in /usr/local/lib/python3.10/site-packages (from oss2->funasr) (1.16.0)\n",
      "Requirement already satisfied: protobuf>=3.20 in /usr/local/lib/python3.10/site-packages (from tensorboardX->funasr) (3.20.3)\n",
      "Requirement already satisfied: pynndescent>=0.5 in /usr/local/lib/python3.10/site-packages (from umap-learn->funasr) (0.5.13)\n",
      "Requirement already satisfied: cryptography>=2.6.0 in /usr/local/lib/python3.10/site-packages (from aliyun-python-sdk-core>=2.13.12->oss2->funasr) (43.0.0)\n",
      "Requirement already satisfied: jmespath<1.0.0,>=0.9.3 in /usr/local/lib/python3.10/site-packages (from aliyun-python-sdk-core>=2.13.12->oss2->funasr) (0.10.0)\n",
      "Requirement already satisfied: pycparser in /usr/local/lib/python3.10/site-packages (from cffi>=1.0->soundfile>=0.12.1->funasr) (2.22)\n",
      "Requirement already satisfied: llvmlite<0.44,>=0.43.0dev0 in /usr/local/lib/python3.10/site-packages (from numba>=0.51.0->librosa->funasr) (0.43.0)\n",
      "Requirement already satisfied: platformdirs>=2.5.0 in /usr/local/lib/python3.10/site-packages (from pooch>=1.1->librosa->funasr) (4.2.2)\n",
      "Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.10/site-packages (from scikit-learn>=0.20.0->librosa->funasr) (3.5.0)\n",
      "Installing collected packages: modelscope\n",
      "  Attempting uninstall: modelscope\n",
      "    Found existing installation: modelscope 1.18.0\n",
      "    Uninstalling modelscope-1.18.0:\n",
      "      Successfully uninstalled modelscope-1.18.0\n",
      "Successfully installed modelscope-1.18.1\n",
      "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
      "\u001b[0m\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip install -U funasr modelscope"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "22fdb82a-5477-4073-adf6-8b9ca845963d",
   "metadata": {
    "ExecutionIndicator": {
     "show": true
    },
    "execution": {
     "iopub.execute_input": "2024-09-25T01:15:06.393064Z",
     "iopub.status.busy": "2024-09-25T01:15:06.392722Z",
     "iopub.status.idle": "2024-09-25T01:15:41.719110Z",
     "shell.execute_reply": "2024-09-25T01:15:41.718548Z",
     "shell.execute_reply.started": "2024-09-25T01:15:06.393043Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "funasr version: 1.1.6.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-09-25 09:15:10,872 - modelscope - INFO - Use user-specified model revision: v2.0.4\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a47bfd0241804c759233a4bc6c603aa1",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [am.mvn]:   0%|          | 0.00/10.9k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "7e2d6bdf8eb749a1929aa22bfd29d036",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [example/asr_example.wav]:   0%|          | 0.00/141k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e2b8a9eccada467989380cb455d01aef",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [config.yaml]:   0%|          | 0.00/3.34k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4a3f9d1308784bddb337da6283850eee",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [configuration.json]:   0%|          | 0.00/478 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8adf71829e3e4c13b6d979ea4079ff7b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [example/hotword.txt]:   0%|          | 0.00/7.00 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "bc1f66d1678d410c86c6e76f3ec7eb20",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [model.pt]:   0%|          | 0.00/944M [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "3e73f5f8cf5446588b31b82e0cb168df",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [README.md]:   0%|          | 0.00/11.3k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "568547cc732d443c9c6ecf075da2b6ed",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [fig/res.png]:   0%|          | 0.00/192k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "53da6948900c4e7485f107b34dfc22dd",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [fig/seaco.png]:   0%|          | 0.00/167k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "287298562d71416a8b1fb8638cb7ba4c",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [seg_dict]:   0%|          | 0.00/7.90M [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f7165f43973c4385893e0aefdf17a540",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [tokens.json]:   0%|          | 0.00/91.5k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-09-25 09:15:24,156 - modelscope - INFO - Use user-specified model revision: v2.0.4\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e2c948d96f6e4ae3ac4cff0d31535b44",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [am.mvn]:   0%|          | 0.00/7.85k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "6c6fdec67ec846048bb9637ba1ee0f26",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [config.yaml]:   0%|          | 0.00/1.19k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "537fa35d55534c15b39e3ccc38484c4c",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [configuration.json]:   0%|          | 0.00/365 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1ede5cdc3b9f425abfb38594754d6171",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [model.pt]:   0%|          | 0.00/1.64M [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "319cce7f5dfc46df8f821f575bef0e70",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [README.md]:   0%|          | 0.00/8.45k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "eb300de41ea24e54a1001ce73fb0eab6",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [fig/struct.png]:   0%|          | 0.00/27.3k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "dcc7bbe25f1344f9a8d1341fd71972fc",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [example/vad_example.wav]:   0%|          | 0.00/2.16M [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-09-25 09:15:28,478 - modelscope - INFO - Use user-specified model revision: v2.0.4\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "9dedf1060292451cb8b214122fc5ff74",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [.DS_Store]:   0%|          | 0.00/6.00k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "27a82ddfcc8f48e8a0552ff91f10acfe",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [config.yaml]:   0%|          | 0.00/810 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e853256ccc1b4dda8d15d5e97fbc39fd",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [configuration.json]:   0%|          | 0.00/373 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "fbe121424e324a5db47f161cb781f85a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [model.pt]:   0%|          | 0.00/278M [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c5c11a4665c847c8886e330b9221b523",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [example/punc_example.txt]:   0%|          | 0.00/863 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "6f5abfa7e4e94d2eb9fd84aaddfa7e2a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [README.md]:   0%|          | 0.00/11.2k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b7a6e0616e2948b8aa327ab1c2bcbc50",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [fig/struct.png]:   0%|          | 0.00/151k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "90c0e9d43eb54d80ba09cc33a308fd3a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [tokens.json]:   0%|          | 0.00/4.01M [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-09-25 09:15:35,555 - modelscope - INFO - Use user-specified model revision: v2.0.2\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "292eb64db37841f8826c7d442440fec2",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [campplus_cn_common.bin]:   0%|          | 0.00/26.7M [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ed00a6d0caaf46e5a972c1f90d9214bf",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [config.yaml]:   0%|          | 0.00/537 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a10f9a7e62744314bfc909585cabccef",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [configuration.json]:   0%|          | 0.00/581 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "86940b15bc8c47db8e40eddb1027509c",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [dingding.jpg]:   0%|          | 0.00/180k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "bec5f67ff1a94921ab93b9c45ec6cc2a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [quickstart.md]:   0%|          | 0.00/1.49k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "153f8ffeaeae49c19d220e28cf700036",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [README.md]:   0%|          | 0.00/5.86k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "51a9325b0a184245a8947a061d3afd3c",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [examples/speaker1_a_cn_16k.wav]:   0%|          | 0.00/116k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2c4a731f5fb64813ade549ebf48adfa8",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [examples/speaker1_b_cn_16k.wav]:   0%|          | 0.00/153k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "5ca91b3e9eea426ca6e73a0c38112667",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [examples/speaker2_a_cn_16k.wav]:   0%|          | 0.00/166k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "aac2279732c341959e17205ff611e85a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading [structure.png]:   0%|          | 0.00/279k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from funasr import AutoModel\n",
    "\n",
    "# from funasr import AutoModel\n",
    "# paraformer-zh is a multi-functional asr model\n",
    "# use vad, punc, spk or not as you need\n",
    "model_pf = AutoModel(\n",
    "                  model=\"paraformer-zh\", model_revision=\"v2.0.4\",\n",
    "                  vad_model=\"fsmn-vad\", vad_model_revision=\"v2.0.4\",\n",
    "                  punc_model=\"ct-punc-c\", punc_model_revision=\"v2.0.4\",\n",
    "                  spk_model=\"cam++\", spk_model_revision=\"v2.0.2\",\n",
    "                  disable_update=True,\n",
    "                  vad_kwargs={\"max_single_segment_time\": 10000},\n",
    "                  # device=\"cuda:0\",hub=\"hf\"\n",
    "                  )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "01c9aaf4-6318-49a6-97b5-4d516f1c7125",
   "metadata": {
    "ExecutionIndicator": {
     "show": true
    },
    "execution": {
     "iopub.execute_input": "2024-09-25T02:23:51.622700Z",
     "iopub.status.busy": "2024-09-25T02:23:51.622274Z",
     "iopub.status.idle": "2024-09-25T02:24:00.091564Z",
     "shell.execute_reply": "2024-09-25T02:24:00.090970Z",
     "shell.execute_reply.started": "2024-09-25T02:23:51.622681Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "rtf_avg: 0.008: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.83it/s]                                                                                          \n",
      "  0%|\u001b[31m          \u001b[0m| 0/1 [00:00<?, ?it/s]\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.30it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.435', 'batch_size': '1', 'rtf': '0.382'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.30it/s]\u001b[A\n",
      "rtf_avg: 0.382: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.28it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.001', 'forward': '0.041', 'batch_size': '1', 'rtf': '0.028'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00, 23.93it/s]\u001b[A\n",
      "rtf_avg: 0.028: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00, 23.08it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.77it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.566', 'batch_size': '1', 'rtf': '0.160'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.77it/s]\u001b[A\n",
      "rtf_avg: 0.160: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.76it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/4 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.004', 'forward': '0.076', 'batch_size': '1', 'rtf': '0.013'}, : 100%|\u001b[34m██████████\u001b[0m| 4/4 [00:00<00:00, 51.91it/s]\u001b[A\n",
      "rtf_avg: 0.013: 100%|\u001b[34m██████████\u001b[0m| 4/4 [00:00<00:00, 50.85it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.03it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.493', 'batch_size': '1', 'rtf': '0.137'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.03it/s]\u001b[A\n",
      "rtf_avg: 0.137: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.02it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/4 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.004', 'forward': '0.072', 'batch_size': '1', 'rtf': '0.012'}, : 100%|\u001b[34m██████████\u001b[0m| 4/4 [00:00<00:00, 54.85it/s]\u001b[A\n",
      "rtf_avg: 0.012: 100%|\u001b[34m██████████\u001b[0m| 4/4 [00:00<00:00, 46.78it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.96it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.003', 'forward': '0.510', 'batch_size': '1', 'rtf': '0.108'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.96it/s]\u001b[A\n",
      "rtf_avg: 0.108: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.95it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/6 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.006', 'forward': '0.090', 'batch_size': '1', 'rtf': '0.010'}, : 100%|\u001b[34m██████████\u001b[0m| 6/6 [00:00<00:00, 66.41it/s]\u001b[A\n",
      "rtf_avg: 0.010: 100%|\u001b[34m██████████\u001b[0m| 6/6 [00:00<00:00, 64.93it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.90it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.525', 'batch_size': '1', 'rtf': '0.094'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.90it/s]\u001b[A\n",
      "rtf_avg: 0.094: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.89it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/7 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.007', 'forward': '0.096', 'batch_size': '1', 'rtf': '0.009'}, : 100%|\u001b[34m██████████\u001b[0m| 7/7 [00:00<00:00, 72.29it/s]\u001b[A\n",
      "rtf_avg: 0.009: 100%|\u001b[34m██████████\u001b[0m| 7/7 [00:00<00:00, 71.11it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.79it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.557', 'batch_size': '1', 'rtf': '0.098'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.79it/s]\u001b[A\n",
      "rtf_avg: 0.098: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.78it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/7 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.007', 'forward': '0.098', 'batch_size': '1', 'rtf': '0.009'}, : 100%|\u001b[34m██████████\u001b[0m| 7/7 [00:00<00:00, 71.09it/s]\u001b[A\n",
      "rtf_avg: 0.009: 100%|\u001b[34m██████████\u001b[0m| 7/7 [00:00<00:00, 69.99it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.77it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.003', 'forward': '0.566', 'batch_size': '1', 'rtf': '0.067'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.77it/s]\u001b[A\n",
      "rtf_avg: 0.067: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.75it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/11 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 11/11 [00:00<00:00, 70.34it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.013', 'forward': '0.156', 'batch_size': '1', 'rtf': '0.009'}, : 100%|\u001b[34m██████████\u001b[0m| 11/11 [00:00<00:00, 70.34it/s]\u001b[A\n",
      "rtf_avg: 0.009: 100%|\u001b[34m██████████\u001b[0m| 11/11 [00:00<00:00, 69.05it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.68it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.003', 'forward': '0.596', 'batch_size': '1', 'rtf': '0.059'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.68it/s]\u001b[A\n",
      "rtf_avg: 0.059: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.67it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/13 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 13/13 [00:00<00:00, 90.03it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.013', 'forward': '0.144', 'batch_size': '1', 'rtf': '0.007'}, : 100%|\u001b[34m██████████\u001b[0m| 13/13 [00:00<00:00, 90.03it/s]\u001b[A\n",
      "rtf_avg: 0.007: 100%|\u001b[34m██████████\u001b[0m| 13/13 [00:00<00:00, 88.27it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': 0.0, 'extract_feat': 0.0, 'forward': '0.055', 'batch_size': '1', 'rtf': '-0.055'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00, 18.21it/s]\u001b[A\n",
      "rtf_avg: -0.055: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00, 17.73it/s]                                                                                  \u001b[A\n",
      "rtf_avg: 0.115, time_speech:  46.440, time_escape: 5.342: 100%|\u001b[31m██████████\u001b[0m| 1/1 [00:05<00:00,  5.36s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "时间差为：8.464286088943481 秒\n",
      "spk0(0.82-3.46s):你好你好唉你你好，\n",
      "spk1(3.46-4.5s):我是芒果的，\n",
      "spk1(4.5-6.62s):我看咱浏览华润十四层的房子了，\n",
      "spk1(6.62-7.56s):咱是想买吗？\n",
      "spk0(8.62-8.86s):啊，\n",
      "spk0(8.88-10.315s):我了解一下啊，\n",
      "spk1(10.87-12.61s):嗯那咱俩加个微信呢，\n",
      "spk1(12.95-14.025s):帮你介绍一下。\n",
      "spk0(15.63-15.87s):嗯，\n",
      "spk0(16.27-16.63s):不用，\n",
      "spk0(16.63-17.41s):我看了一下，\n",
      "spk0(17.41-18.39s):就是我可以，\n",
      "spk0(18.39-25.57s):你是你在那个我我可以就是那个搁搁那个什么里边跟你聊问了，\n",
      "spk0(25.57-27.81s):问一下哪二楼完事多少层，\n",
      "spk0(27.87-30.19s):我了解一下这个情况哦，\n",
      "spk0(30.79-31.37s):我知道，\n",
      "spk0(31.53-34.15s):但是你加一下这个啊，\n",
      "spk1(34.37-35.73s):你不是有需求吗？\n",
      "spk1(35.79-37.07s):你想要什么样的房子，\n",
      "spk1(37.07-39.025s):我不就可以直接发给你吗？\n",
      "spk0(40.58-40.82s):啊，\n",
      "spk0(40.82-41.2s):没事，\n",
      "spk0(41.2-41.74s):不用我，\n",
      "spk0(41.74-42.34s):我不想加，\n",
      "spk0(42.34-43.04s):那我的微信。\n",
      "spk0(43.5-43.74s):嗯，\n",
      "spk0(43.84-44.04s):行，\n",
      "spk0(44.04-45.955s):那好了再见嗯。\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "\n",
    "# fileName = \"right_channel\"\n",
    "fileName = \"demo3\"\n",
    "start_time = time.time()\n",
    "# res = model_pf.generate(input=f\"/mnt/workspace/notebook_hub_ms/demo/{fileName}.mp3\",\n",
    "#                         batch_size_s=300,\n",
    "#                         # merge_vad = True,\n",
    "#                         hotword='标价 20, 多钱 40')\n",
    "res = model_pf.generate(input=\"https://d1.33e9cloud.com/e0f6d0e3f79f4589a56e05878850677d/2625861b26344c06b4732eb098deda5e/2024092113/15998861663_13889813079_20240921130709_202409211307001683922033103.mp3?auth=BDA8613701360638F6778AD933AEDFBF\",\n",
    "                        batch_size_s=300,\n",
    "                        # merge_vad = True,\n",
    "                        hotword='标价 20, 多钱 40')\n",
    "end_time = time.time()\n",
    "end_time = time.time()\n",
    "time_diff = (end_time - start_time)\n",
    "print(f\"时间差为：{time_diff} 秒\")\n",
    "# print(res[0][\"sentence_info\"])\n",
    "data_list = res[0][\"sentence_info\"]\n",
    "for item in data_list:\n",
    "    # speaker = \"spk0\" if item['spk'] == 0 else \"spk1\"\n",
    "    item_msg = f\"spk{item['spk']}({item['start']/1000}-{item['end']/1000}s):{item['text']}\"\n",
    "    print(item_msg)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "f8681d77-4002-4a7c-ac83-009e07eb1635",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-09-25T01:19:27.612860Z",
     "iopub.status.busy": "2024-09-25T01:19:27.612546Z",
     "iopub.status.idle": "2024-09-25T01:19:35.494537Z",
     "shell.execute_reply": "2024-09-25T01:19:35.493913Z",
     "shell.execute_reply.started": "2024-09-25T01:19:27.612842Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://mirrors.cloud.aliyuncs.com/pypi/simple\n",
      "Collecting gradio\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/00/ce/9c969f7c591c21cd0f419b6cd95273cdcd4efbc6dce3b75b619b821d71fb/gradio-4.44.0-py3-none-any.whl (18.1 MB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m18.1/18.1 MB\u001b[0m \u001b[31m92.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
      "\u001b[?25hCollecting pydub\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/a6/53/d78dc063216e62fc55f6b2eebb447f6a4b0a59f55c8406376f76bf959b08/pydub-0.25.1-py2.py3-none-any.whl (32 kB)\n",
      "Requirement already satisfied: typer<1.0,>=0.12 in /usr/local/lib/python3.10/site-packages (from gradio) (0.12.3)\n",
      "Requirement already satisfied: urllib3~=2.0 in /usr/local/lib/python3.10/site-packages (from gradio) (2.2.1)\n",
      "Requirement already satisfied: python-multipart>=0.0.9 in /usr/local/lib/python3.10/site-packages (from gradio) (0.0.9)\n",
      "Requirement already satisfied: markupsafe~=2.0 in /usr/local/lib/python3.10/site-packages (from gradio) (2.1.5)\n",
      "Collecting ffmpy\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/ff/1e/db99aa669eee301966bc6c997d60a0240f9cecae63f044b2e5a5310e4bf7/ffmpy-0.4.0-py3-none-any.whl (5.8 kB)\n",
      "Requirement already satisfied: matplotlib~=3.0 in /usr/local/lib/python3.10/site-packages (from gradio) (3.9.0)\n",
      "Requirement already satisfied: pyyaml<7.0,>=5.0 in /usr/local/lib/python3.10/site-packages (from gradio) (6.0.1)\n",
      "Requirement already satisfied: huggingface-hub>=0.19.3 in /usr/local/lib/python3.10/site-packages (from gradio) (0.24.2)\n",
      "Requirement already satisfied: jinja2<4.0 in /usr/local/lib/python3.10/site-packages (from gradio) (3.1.4)\n",
      "Collecting ruff>=0.2.2\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/9f/55/53f10c1bd8c3b2ae79aed18e62b22c6346f9296aa0ec80489b8442bd06a9/ruff-0.6.7-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.8 MB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m10.8/10.8 MB\u001b[0m \u001b[31m125.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
      "\u001b[?25hCollecting gradio-client==1.3.0\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/de/fe/7e9cb4d0e6aa74268fa31089189e4855882a0f2a36c45d359336946d4ae1/gradio_client-1.3.0-py3-none-any.whl (318 kB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m318.7/318.7 kB\u001b[0m \u001b[31m72.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[?25hRequirement already satisfied: anyio<5.0,>=3.0 in /usr/local/lib/python3.10/site-packages (from gradio) (4.4.0)\n",
      "Requirement already satisfied: fastapi<1.0 in /usr/local/lib/python3.10/site-packages (from gradio) (0.111.1)\n",
      "Collecting semantic-version~=2.0\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/6a/23/8146aad7d88f4fcb3a6218f41a60f6c2d4e3a72de72da1825dc7c8f7877c/semantic_version-2.10.0-py2.py3-none-any.whl (15 kB)\n",
      "Collecting aiofiles<24.0,>=22.0\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/c5/19/5af6804c4cc0fed83f47bff6e413a98a36618e7d40185cd36e69737f3b0e/aiofiles-23.2.1-py3-none-any.whl (15 kB)\n",
      "Requirement already satisfied: pandas<3.0,>=1.0 in /usr/local/lib/python3.10/site-packages (from gradio) (2.2.2)\n",
      "Requirement already satisfied: pydantic>=2.0 in /usr/local/lib/python3.10/site-packages (from gradio) (2.7.2)\n",
      "Requirement already satisfied: httpx>=0.24.1 in /usr/local/lib/python3.10/site-packages (from gradio) (0.27.0)\n",
      "Collecting importlib-resources<7.0,>=1.3\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/e1/6a/4604f9ae2fa62ef47b9de2fa5ad599589d28c9fd1d335f32759813dfa91e/importlib_resources-6.4.5-py3-none-any.whl (36 kB)\n",
      "Collecting orjson~=3.0\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/b6/bc/fbd345d771a73cacc5b0e774d034cd081590b336754c511f4ead9fdc4cf1/orjson-3.10.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (141 kB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m141.9/141.9 kB\u001b[0m \u001b[31m56.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[?25hRequirement already satisfied: typing-extensions~=4.0 in /usr/local/lib/python3.10/site-packages (from gradio) (4.12.0)\n",
      "Requirement already satisfied: uvicorn>=0.14.0 in /usr/local/lib/python3.10/site-packages (from gradio) (0.30.3)\n",
      "Requirement already satisfied: pillow<11.0,>=8.0 in /usr/local/lib/python3.10/site-packages (from gradio) (10.3.0)\n",
      "Requirement already satisfied: numpy<3.0,>=1.0 in /usr/local/lib/python3.10/site-packages (from gradio) (1.26.4)\n",
      "Collecting tomlkit==0.12.0\n",
      "  Downloading https://mirrors.cloud.aliyuncs.com/pypi/packages/68/4f/12207897848a653d03ebbf6775a29d949408ded5f99b2d87198bc5c93508/tomlkit-0.12.0-py3-none-any.whl (37 kB)\n",
      "Requirement already satisfied: packaging in /usr/local/lib/python3.10/site-packages (from gradio) (24.0)\n",
      "Requirement already satisfied: fsspec in /usr/local/lib/python3.10/site-packages (from gradio-client==1.3.0->gradio) (2024.5.0)\n",
      "Requirement already satisfied: websockets<13.0,>=10.0 in /usr/local/lib/python3.10/site-packages (from gradio-client==1.3.0->gradio) (12.0)\n",
      "Requirement already satisfied: exceptiongroup>=1.0.2 in /usr/local/lib/python3.10/site-packages (from anyio<5.0,>=3.0->gradio) (1.2.1)\n",
      "Requirement already satisfied: sniffio>=1.1 in /usr/local/lib/python3.10/site-packages (from anyio<5.0,>=3.0->gradio) (1.3.1)\n",
      "Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.10/site-packages (from anyio<5.0,>=3.0->gradio) (3.7)\n",
      "Requirement already satisfied: starlette<0.38.0,>=0.37.2 in /usr/local/lib/python3.10/site-packages (from fastapi<1.0->gradio) (0.37.2)\n",
      "Requirement already satisfied: email_validator>=2.0.0 in /usr/local/lib/python3.10/site-packages (from fastapi<1.0->gradio) (2.2.0)\n",
      "Requirement already satisfied: fastapi-cli>=0.0.2 in /usr/local/lib/python3.10/site-packages (from fastapi<1.0->gradio) (0.0.4)\n",
      "Requirement already satisfied: certifi in /usr/local/lib/python3.10/site-packages (from httpx>=0.24.1->gradio) (2024.2.2)\n",
      "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/site-packages (from httpx>=0.24.1->gradio) (1.0.5)\n",
      "Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.10/site-packages (from httpcore==1.*->httpx>=0.24.1->gradio) (0.14.0)\n",
      "Requirement already satisfied: filelock in /usr/local/lib/python3.10/site-packages (from huggingface-hub>=0.19.3->gradio) (3.14.0)\n",
      "Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/site-packages (from huggingface-hub>=0.19.3->gradio) (4.66.4)\n",
      "Requirement already satisfied: requests in /usr/local/lib/python3.10/site-packages (from huggingface-hub>=0.19.3->gradio) (2.32.3)\n",
      "Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.10/site-packages (from matplotlib~=3.0->gradio) (1.4.5)\n",
      "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/site-packages (from matplotlib~=3.0->gradio) (2.9.0.post0)\n",
      "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/site-packages (from matplotlib~=3.0->gradio) (1.2.1)\n",
      "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/site-packages (from matplotlib~=3.0->gradio) (0.12.1)\n",
      "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/site-packages (from matplotlib~=3.0->gradio) (3.1.2)\n",
      "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/site-packages (from matplotlib~=3.0->gradio) (4.53.0)\n",
      "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/site-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n",
      "Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.10/site-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n",
      "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/site-packages (from pydantic>=2.0->gradio) (0.7.0)\n",
      "Requirement already satisfied: pydantic-core==2.18.3 in /usr/local/lib/python3.10/site-packages (from pydantic>=2.0->gradio) (2.18.3)\n",
      "Requirement already satisfied: rich>=10.11.0 in /usr/local/lib/python3.10/site-packages (from typer<1.0,>=0.12->gradio) (13.7.1)\n",
      "Requirement already satisfied: shellingham>=1.3.0 in /usr/local/lib/python3.10/site-packages (from typer<1.0,>=0.12->gradio) (1.5.4)\n",
      "Requirement already satisfied: click>=8.0.0 in /usr/local/lib/python3.10/site-packages (from typer<1.0,>=0.12->gradio) (8.1.7)\n",
      "Requirement already satisfied: dnspython>=2.0.0 in /usr/local/lib/python3.10/site-packages (from email_validator>=2.0.0->fastapi<1.0->gradio) (2.3.0)\n",
      "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio) (1.16.0)\n",
      "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (2.18.0)\n",
      "Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.10/site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (3.0.0)\n",
      "Requirement already satisfied: uvloop!=0.15.0,!=0.15.1,>=0.14.0 in /usr/local/lib/python3.10/site-packages (from uvicorn>=0.14.0->gradio) (0.19.0)\n",
      "Requirement already satisfied: python-dotenv>=0.13 in /usr/local/lib/python3.10/site-packages (from uvicorn>=0.14.0->gradio) (1.0.1)\n",
      "Requirement already satisfied: watchfiles>=0.13 in /usr/local/lib/python3.10/site-packages (from uvicorn>=0.14.0->gradio) (0.22.0)\n",
      "Requirement already satisfied: httptools>=0.5.0 in /usr/local/lib/python3.10/site-packages (from uvicorn>=0.14.0->gradio) (0.6.1)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/site-packages (from requests->huggingface-hub>=0.19.3->gradio) (3.3.2)\n",
      "Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.10/site-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio) (0.1.2)\n",
      "Installing collected packages: pydub, tomlkit, semantic-version, ruff, orjson, importlib-resources, ffmpy, aiofiles, gradio-client, gradio\n",
      "Successfully installed aiofiles-23.2.1 ffmpy-0.4.0 gradio-4.44.0 gradio-client-1.3.0 importlib-resources-6.4.5 orjson-3.10.7 pydub-0.25.1 ruff-0.6.7 semantic-version-2.10.0 tomlkit-0.12.0\n",
      "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
      "\u001b[0m\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip install gradio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "98b247ea-dc26-4d68-b0f3-b2905b243180",
   "metadata": {
    "ExecutionIndicator": {
     "show": false
    },
    "execution": {
     "iopub.execute_input": "2024-09-25T04:00:12.475279Z",
     "iopub.status.busy": "2024-09-25T04:00:12.474947Z",
     "iopub.status.idle": "2024-09-25T04:00:14.690445Z",
     "shell.execute_reply": "2024-09-25T04:00:14.689905Z",
     "shell.execute_reply.started": "2024-09-25T04:00:12.475260Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Running on local URL:  http://0.0.0.0:8823\n",
      "\n",
      "To create a public link, set `share=True` in `launch()`.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div><iframe src=\"http://localhost:8823/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": []
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "rtf_avg: 0.007: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.92it/s]                                                                                          \n",
      "  0%|\u001b[31m          \u001b[0m| 0/1 [00:00<?, ?it/s]\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.63it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.381', 'batch_size': '1', 'rtf': '0.334'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.63it/s]\u001b[A\n",
      "rtf_avg: 0.334: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.60it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.001', 'forward': '0.038', 'batch_size': '1', 'rtf': '0.025'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00, 25.79it/s]\u001b[A\n",
      "rtf_avg: 0.025: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00, 24.83it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.25it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.445', 'batch_size': '1', 'rtf': '0.126'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.25it/s]\u001b[A\n",
      "rtf_avg: 0.126: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.23it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/4 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.004', 'forward': '0.076', 'batch_size': '1', 'rtf': '0.013'}, : 100%|\u001b[34m██████████\u001b[0m| 4/4 [00:00<00:00, 52.02it/s]\u001b[A\n",
      "rtf_avg: 0.013: 100%|\u001b[34m██████████\u001b[0m| 4/4 [00:00<00:00, 50.82it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.13it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.470', 'batch_size': '1', 'rtf': '0.131'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.13it/s]\u001b[A\n",
      "rtf_avg: 0.131: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.11it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/4 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.004', 'forward': '0.072', 'batch_size': '1', 'rtf': '0.012'}, : 100%|\u001b[34m██████████\u001b[0m| 4/4 [00:00<00:00, 55.39it/s]\u001b[A\n",
      "rtf_avg: 0.012: 100%|\u001b[34m██████████\u001b[0m| 4/4 [00:00<00:00, 54.16it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.10it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.476', 'batch_size': '1', 'rtf': '0.100'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.10it/s]\u001b[A\n",
      "rtf_avg: 0.100: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.08it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/6 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.006', 'forward': '0.093', 'batch_size': '1', 'rtf': '0.010'}, : 100%|\u001b[34m██████████\u001b[0m| 6/6 [00:00<00:00, 64.38it/s]\u001b[A\n",
      "rtf_avg: 0.010: 100%|\u001b[34m██████████\u001b[0m| 6/6 [00:00<00:00, 62.96it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.02it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.003', 'forward': '0.496', 'batch_size': '1', 'rtf': '0.089'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.02it/s]\u001b[A\n",
      "rtf_avg: 0.089: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.00it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/7 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 7/7 [00:00<00:00, 67.88it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.007', 'forward': '0.103', 'batch_size': '1', 'rtf': '0.010'}, : 100%|\u001b[34m██████████\u001b[0m| 7/7 [00:00<00:00, 67.88it/s]\u001b[A\n",
      "rtf_avg: 0.010: 100%|\u001b[34m██████████\u001b[0m| 7/7 [00:00<00:00, 65.87it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.98it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.504', 'batch_size': '1', 'rtf': '0.088'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.98it/s]\u001b[A\n",
      "rtf_avg: 0.088: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.97it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/7 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.007', 'forward': '0.099', 'batch_size': '1', 'rtf': '0.009'}, : 100%|\u001b[34m██████████\u001b[0m| 7/7 [00:00<00:00, 70.47it/s]\u001b[A\n",
      "rtf_avg: 0.009: 100%|\u001b[34m██████████\u001b[0m| 7/7 [00:00<00:00, 68.93it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.85it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.003', 'forward': '0.541', 'batch_size': '1', 'rtf': '0.064'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.85it/s]\u001b[A\n",
      "rtf_avg: 0.064: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.84it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/11 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 11/11 [00:00<00:00, 83.64it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.011', 'forward': '0.131', 'batch_size': '1', 'rtf': '0.008'}, : 100%|\u001b[34m██████████\u001b[0m| 11/11 [00:00<00:00, 83.64it/s]\u001b[A\n",
      "rtf_avg: 0.008: 100%|\u001b[34m██████████\u001b[0m| 11/11 [00:00<00:00, 81.64it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.69it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.003', 'forward': '0.591', 'batch_size': '1', 'rtf': '0.059'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.69it/s]\u001b[A\n",
      "rtf_avg: 0.059: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  1.68it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/13 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 13/13 [00:00<00:00, 90.57it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.012', 'forward': '0.144', 'batch_size': '1', 'rtf': '0.007'}, : 100%|\u001b[34m██████████\u001b[0m| 13/13 [00:00<00:00, 90.57it/s]\u001b[A\n",
      "rtf_avg: 0.007: 100%|\u001b[34m██████████\u001b[0m| 13/13 [00:00<00:00, 88.64it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': 0.0, 'extract_feat': 0.0, 'forward': '0.054', 'batch_size': '1', 'rtf': '-0.054'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00, 18.34it/s]\u001b[A\n",
      "rtf_avg: -0.054: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00, 17.80it/s]                                                                                  \u001b[A\n",
      "rtf_avg: 0.105, time_speech:  46.440, time_escape: 4.857: 100%|\u001b[31m██████████\u001b[0m| 1/1 [00:04<00:00,  4.88s/it]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "时间差为：5.223354816436768 秒\n",
      "spk0(0.82-3.46s):你好你好唉你你好，\n",
      "spk1(3.46-4.5s):我是芒果的，\n",
      "spk1(4.5-6.62s):我看咱浏览华润十四层的房子了，\n",
      "spk1(6.62-7.56s):咱是想买吗？\n",
      "spk0(8.62-8.86s):啊，\n",
      "spk0(8.88-10.315s):我了解一下啊，\n",
      "spk1(10.87-12.61s):嗯那咱俩加个微信呢，\n",
      "spk1(12.95-14.025s):帮你介绍一下。\n",
      "spk0(15.63-15.87s):嗯，\n",
      "spk0(16.27-16.63s):不用，\n",
      "spk0(16.63-17.41s):我看了一下，\n",
      "spk0(17.41-18.39s):就是我可以，\n",
      "spk0(18.39-25.57s):你是你在那个我我可以就是那个搁搁那个什么里边跟你聊问了，\n",
      "spk0(25.57-27.81s):问一下哪二楼完事多少层，\n",
      "spk0(27.87-30.19s):我了解一下这个情况哦，\n",
      "spk0(30.79-31.37s):我知道，\n",
      "spk0(31.53-34.15s):但是你加一下这个啊，\n",
      "spk1(34.37-35.73s):你不是有需求吗？\n",
      "spk1(35.79-37.07s):你想要什么样的房子，\n",
      "spk1(37.07-39.025s):我不就可以直接发给你吗？\n",
      "spk0(40.58-40.82s):啊，\n",
      "spk0(40.82-41.2s):没事，\n",
      "spk0(41.2-41.74s):不用我，\n",
      "spk0(41.74-42.34s):我不想加，\n",
      "spk0(42.34-43.04s):那我的微信。\n",
      "spk0(43.5-43.74s):嗯，\n",
      "spk0(43.84-44.04s):行，\n",
      "spk0(44.04-45.955s):那好了再见嗯。\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "rtf_avg: 0.007: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  4.32it/s]                                                                                          \n",
      "  0%|\u001b[31m          \u001b[0m| 0/1 [00:00<?, ?it/s]\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.92it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.342', 'batch_size': '1', 'rtf': '0.407'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.92it/s]\u001b[A\n",
      "rtf_avg: 0.407: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.90it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.041', 'batch_size': '1', 'rtf': '0.027'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00, 24.11it/s]\u001b[A\n",
      "rtf_avg: 0.027: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00, 23.26it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.96it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.001', 'forward': '0.338', 'batch_size': '1', 'rtf': '0.376'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.96it/s]\u001b[A\n",
      "rtf_avg: 0.376: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.93it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.001', 'forward': '0.039', 'batch_size': '1', 'rtf': '0.026'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00, 25.49it/s]\u001b[A\n",
      "rtf_avg: 0.026: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00, 24.58it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.50it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.399', 'batch_size': '1', 'rtf': '0.222'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.50it/s]\u001b[A\n",
      "rtf_avg: 0.222: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.49it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/2 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.090', 'batch_size': '1', 'rtf': '0.030'}, : 100%|\u001b[34m██████████\u001b[0m| 2/2 [00:00<00:00, 22.01it/s]\u001b[A\n",
      "rtf_avg: 0.030: 100%|\u001b[34m██████████\u001b[0m| 2/2 [00:00<00:00, 21.64it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.14it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.468', 'batch_size': '1', 'rtf': '0.156'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.14it/s]\u001b[A\n",
      "rtf_avg: 0.156: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.12it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/4 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.004', 'forward': '0.081', 'batch_size': '1', 'rtf': '0.013'}, : 100%|\u001b[34m██████████\u001b[0m| 4/4 [00:00<00:00, 49.07it/s]\u001b[A\n",
      "rtf_avg: 0.013: 100%|\u001b[34m██████████\u001b[0m| 4/4 [00:00<00:00, 48.16it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.30it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.435', 'batch_size': '1', 'rtf': '0.145'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.30it/s]\u001b[A\n",
      "rtf_avg: 0.145: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.28it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/4 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.004', 'forward': '0.073', 'batch_size': '1', 'rtf': '0.012'}, : 100%|\u001b[34m██████████\u001b[0m| 4/4 [00:00<00:00, 54.50it/s]\u001b[A\n",
      "rtf_avg: 0.012: 100%|\u001b[34m██████████\u001b[0m| 4/4 [00:00<00:00, 53.39it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.24it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.447', 'batch_size': '1', 'rtf': '0.135'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.24it/s]\u001b[A\n",
      "rtf_avg: 0.135: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.22it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/4 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.004', 'forward': '0.074', 'batch_size': '1', 'rtf': '0.012'}, : 100%|\u001b[34m██████████\u001b[0m| 4/4 [00:00<00:00, 53.94it/s]\u001b[A\n",
      "rtf_avg: 0.012: 100%|\u001b[34m██████████\u001b[0m| 4/4 [00:00<00:00, 52.67it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.21it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.452', 'batch_size': '1', 'rtf': '0.114'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.21it/s]\u001b[A\n",
      "rtf_avg: 0.114: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.20it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/5 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 5/5 [00:00<00:00, 42.89it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.005', 'forward': '0.117', 'batch_size': '1', 'rtf': '0.016'}, : 100%|\u001b[34m██████████\u001b[0m| 5/5 [00:00<00:00, 42.89it/s]\u001b[A\n",
      "rtf_avg: 0.016: 100%|\u001b[34m██████████\u001b[0m| 5/5 [00:00<00:00, 41.81it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.01it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.002', 'forward': '0.497', 'batch_size': '1', 'rtf': '0.098'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.01it/s]\u001b[A\n",
      "rtf_avg: 0.098: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00,  2.00it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/6 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': '0.000', 'extract_feat': '0.006', 'forward': '0.090', 'batch_size': '1', 'rtf': '0.010'}, : 100%|\u001b[34m██████████\u001b[0m| 6/6 [00:00<00:00, 66.04it/s]\u001b[A\n",
      "rtf_avg: 0.010: 100%|\u001b[34m██████████\u001b[0m| 6/6 [00:00<00:00, 64.75it/s]                                                                                          \u001b[A\n",
      "\n",
      "  0%|\u001b[34m          \u001b[0m| 0/1 [00:00<?, ?it/s]\u001b[A\n",
      "{'load_data': 0.0, 'extract_feat': 0.0, 'forward': '0.024', 'batch_size': '1', 'rtf': '-0.024'}, : 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00, 40.40it/s]\u001b[A\n",
      "rtf_avg: -0.024: 100%|\u001b[34m██████████\u001b[0m| 1/1 [00:00<00:00, 37.72it/s]                                                                                  \u001b[A\n",
      "rtf_avg: 0.129, time_speech:  32.112, time_escape: 4.144: 100%|\u001b[31m██████████\u001b[0m| 1/1 [00:04<00:00,  4.16s/it]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "时间差为：4.393945217132568 秒\n",
      "spk0(0.9-2.56s):你好哎，\n",
      "spk1(2.58-2.98s):你好，\n",
      "spk1(3.08-4.4s):我这边是芒果的，\n",
      "spk1(4.62-6.875s):我看您在关注要买房子是吗？\n",
      "spk0(8.12-8.52s):对呀，\n",
      "spk1(9.27-10.85s):你要买现代家园吗？\n",
      "spk1(11.57-13.31s):他嗯，\n",
      "spk1(13.39-16.125s):那您现在是想买多大面积的呀，\n",
      "spk0(17.57-19.03s):一一百四五，\n",
      "spk0(19.21-19.975s):一百五六。\n",
      "spk1(21.43-21.67s):嗯，\n",
      "spk1(21.91-23.845s):您这您那您看房子了吗？\n",
      "spk1(26.5-27.785s):最近看房子了吗？\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import gradio as gr\n",
    "import time\n",
    "\n",
    "def btnclick(audioFile):\n",
    "    if True:\n",
    "        # 这里添加音频处理和识别逻辑\n",
    "        start_time = time.time()\n",
    "        \n",
    "        res = model_pf.generate(input=audioFile,\n",
    "                            batch_size_s=300,\n",
    "                            hotword='标价,多钱')\n",
    "        end_time = time.time()\n",
    "        time_diff = (end_time - start_time)\n",
    "        print(f\"时间差为：{time_diff} 秒\")\n",
    "        # print(res[0][\"sentence_info\"])\n",
    "        data_list = res[0][\"sentence_info\"]\n",
    "        results = \"\"\n",
    "        for item in data_list:\n",
    "            # speaker = \"spk0\" if item['spk'] == 0 else \"spk1\"\n",
    "            item_msg = f\"spk{item['spk']}({item['start']/1000}-{item['end']/1000}s):{item['text']}\"\n",
    "            results += f\"{item_msg}\\n\"\n",
    "            pass\n",
    "        print(results)\n",
    "        return results\n",
    "    return \"没有文件。\"\n",
    "\n",
    "\n",
    "def process(file):\n",
    "    return file # 返回文件和空结果\n",
    "\n",
    "\n",
    "import requests\n",
    "import tempfile\n",
    "# def download_audio(url):\n",
    "#     response = requests.get(url)\n",
    "#     if response.status_code == 200:\n",
    "#         # 将下载的内容保存到临时文件\n",
    "#         with tempfile.NamedTemporaryFile(delete=False, suffix=\".mp3\") as temp_file:\n",
    "#             temp_file.write(response.content)\n",
    "#             return temp_file.name  # 返回临时文件的路径\n",
    "#     return None\n",
    "\n",
    "def download_audio(url):\n",
    "    if len(url)>0:\n",
    "        response = requests.get(url)\n",
    "        if response.status_code == 200:\n",
    "            # 指定保存的文件名\n",
    "            local_filename = \"downloaded_audio.mp3\"\n",
    "            with open(local_filename, 'wb') as f:\n",
    "                f.write(response.content)\n",
    "            return local_filename  # 返回保存的文件路径\n",
    "    return None\n",
    "\n",
    "def btnclick2(txt):\n",
    "    if len(txt)>0:\n",
    "        url = \"https://misapi2020.517api.cn/mangoapi/b1099_Common.Data/AIApiController/ChatGptApiByRule\"\n",
    "        # 38-芒果在线用户来电分析\n",
    "        postData = {\n",
    "                        \"RuleId\": 38,\n",
    "                        \"Values\": [\n",
    "                            {\n",
    "                                \"Key\": \"{{data}}\",\n",
    "                                \"Value\": txt\n",
    "                            }\n",
    "                        ]\n",
    "                    }\n",
    "        response = requests.post(url,json=postData)\n",
    "        if response.status_code == 200:     \n",
    "            # 假设返回的 JSON 格式是 {\"DataBody\":[{...}]}\n",
    "            data = response.json()\n",
    "            # print(response)\n",
    "            if \"DataBody\" in data and len(data[\"DataBody\"]) > 0:\n",
    "                # 处理返回数据\n",
    "                return data[\"DataBody\"][0]  # 根据需要返回合适的内容\n",
    "        else:\n",
    "            return f\"请求失败，状态码: {response.status_code}\"\n",
    "    return None\n",
    "    \n",
    "with gr.Blocks() as demo:\n",
    "    gr.Markdown(\"官网文档：https://www.517.cn\")\n",
    "    # with gr.Tab(\"录音文件识别\"):\n",
    "    #     with gr.Accordion(\"上传录音\"):\n",
    "    #         with gr.Row():\n",
    "    #             file_input = gr.File(label=\"上传 音频 文件\", file_types=[\".mp3\",\".wav\"])\n",
    "    #             audio_output = gr.Audio(label=\"播放音频\")\n",
    "    #             file_input.change(process, inputs=file_input, outputs=audio_output)\n",
    "    #     with gr.Accordion(\"识别\"):\n",
    "    #         with gr.Row():\n",
    "    #             upload_btn = gr.Button(\"识别\")           \n",
    "    #         with gr.Row():\n",
    "    #             output_txt = gr.Textbox(show_label=False, container=False)\n",
    "    #     upload_btn.click(btnclick, inputs=file_input, outputs=output_txt)\n",
    "    with gr.Tab(\"录音文件识别By网址\"):\n",
    "        with gr.Accordion(\"上传录音\"):\n",
    "            with gr.Row():\n",
    "                url_input = gr.Textbox(label=\"音频网址\")\n",
    "            with gr.Row():\n",
    "                file_input1 = gr.File(label=\"上传 音频 文件\", file_types=[\".mp3\",\".wav\"])\n",
    "                audio_output1 = gr.Audio(label=\"播放音频\")\n",
    "                url_input.change(download_audio, inputs=url_input, outputs=file_input1)\n",
    "                file_input1.change(process, inputs=file_input1, outputs=audio_output1)\n",
    "        with gr.Accordion(\"识别\"):\n",
    "            with gr.Row():\n",
    "                upload_btn1 = gr.Button(\"识别\")           \n",
    "            with gr.Row():\n",
    "                output_txt1 = gr.Textbox(label=\"对话内容\")\n",
    "            upload_btn1.click(btnclick, inputs=file_input1, outputs=output_txt1)\n",
    "        with gr.Accordion(\"分析\"):\n",
    "            with gr.Row():\n",
    "                ans_btn = gr.Button(\"分析\")           \n",
    "            with gr.Row():\n",
    "                output_txt2 = gr.Textbox(label=\"分析结果\")\n",
    "            ans_btn.click(btnclick2, inputs=output_txt1, outputs=output_txt2)\n",
    "\n",
    "demo.launch(server_name=\"0.0.0.0\", server_port=8823, share=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "0be75e85-c704-4231-af59-9fa7c5292d61",
   "metadata": {
    "ExecutionIndicator": {
     "show": true
    },
    "execution": {
     "iopub.execute_input": "2024-09-25T01:20:25.253257Z",
     "iopub.status.busy": "2024-09-25T01:20:25.253030Z",
     "iopub.status.idle": "2024-09-25T01:20:35.859752Z",
     "shell.execute_reply": "2024-09-25T01:20:35.859167Z",
     "shell.execute_reply.started": "2024-09-25T01:20:25.253240Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "deb https://ngrok-agent.s3.amazonaws.com buster main\n",
      "获取:1 http://mirrors.aliyun.com/ubuntu jammy InRelease [270 kB]\n",
      "获取:2 http://mirrors.aliyun.com/ubuntu jammy-security InRelease [129 kB]        m\n",
      "获取:3 http://mirrors.aliyun.com/ubuntu jammy-updates InRelease [128 kB]         m\n",
      "获取:4 http://mirrors.aliyun.com/ubuntu jammy-backports InRelease [127 kB]       m\n",
      "获取:5 http://mirrors.aliyun.com/ubuntu jammy/main amd64 Packages [1,792 kB]     m\n",
      "获取:6 http://mirrors.aliyun.com/ubuntu jammy/restricted amd64 Packages [164 kB] m\u001b[33m\n",
      "获取:7 http://mirrors.aliyun.com/ubuntu jammy/universe amd64 Packages [17.5 MB]\n",
      "获取:8 https://ngrok-agent.s3.amazonaws.com buster InRelease [20.3 kB]          \u001b[33m\u001b[33m\n",
      "获取:9 http://mirrors.aliyun.com/ubuntu jammy/multiverse amd64 Packages [266 kB]m\n",
      "获取:10 http://mirrors.aliyun.com/ubuntu jammy-security/restricted amd64 Packages [3,108 kB]\n",
      "获取:11 https://ngrok-agent.s3.amazonaws.com buster/main amd64 Packages [5,874 B]\n",
      "获取:12 http://mirrors.aliyun.com/ubuntu jammy-security/multiverse amd64 Packages [44.7 kB][33m\n",
      "获取:13 http://mirrors.aliyun.com/ubuntu jammy-security/main amd64 Packages [2,314 kB]\n",
      "获取:14 http://mirrors.aliyun.com/ubuntu jammy-security/universe amd64 Packages [1,154 kB]\n",
      "获取:15 http://mirrors.aliyun.com/ubuntu jammy-updates/main amd64 Packages [2,593 kB]\n",
      "获取:16 http://mirrors.aliyun.com/ubuntu jammy-updates/universe amd64 Packages [1,442 kB]\n",
      "获取:17 http://mirrors.aliyun.com/ubuntu jammy-updates/restricted amd64 Packages [3,191 kB]\n",
      "获取:18 http://mirrors.aliyun.com/ubuntu jammy-updates/multiverse amd64 Packages [51.8 kB]\n",
      "获取:19 http://mirrors.aliyun.com/ubuntu jammy-backports/universe amd64 Packages [33.7 kB]\n",
      "获取:20 http://mirrors.aliyun.com/ubuntu jammy-backports/main amd64 Packages [81.4 kB]\n",
      "已下载 34.4 MB，耗时 4秒 (9,216 kB/s)m\u001b[33m                        \u001b[0m\u001b[33m\u001b[33m\n",
      "正在读取软件包列表... 完成%\n",
      "正在分析软件包的依赖关系树... 完成%\n",
      "正在读取状态信息... 完成                   \n",
      "有 67 个软件包可以升级。请执行 ‘apt list --upgradable’ 来查看它们。\n",
      "正在读取软件包列表... 完成%\n",
      "正在分析软件包的依赖关系树... 完成%\n",
      "正在读取状态信息... 完成                   \n",
      "下列【新】软件包将被安装：\n",
      "  ngrok\n",
      "升级了 0 个软件包，新安装了 1 个软件包， 要卸载 0 个软件包，有 67 个软件包未被升级。\n",
      "需要下载 6,572 kB 的归档。\n",
      "解压缩后会消耗 0 B 的额外空间。\n",
      "获取:1 https://ngrok-agent.s3.amazonaws.com buster/main amd64 ngrok amd64 3.16.0 [6,572 kB]\n",
      "已下载 6,572 kB，耗时 3秒 (2,499 kB/s)    \u001b[0m\u001b[33m33m\n",
      "debconf: 无法初始化前端界面：Dialog\n",
      "debconf: (没有安装任何可用的对话框类程序，所以无法使用基于此种形式的界面。 at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 78, <> line 1.)\n",
      "debconf: 返回前端界面：Readline\n",
      "\n",
      "\u001b7\u001b[0;23r\u001b8\u001b[1A正在选中未选择的软件包 ngrok。\n",
      "(正在读取数据库 ... 系统当前共安装有 43533 个文件和目录。)\n",
      "准备解压 .../ngrok_3.16.0_amd64.deb  ...\n",
      "\u001b7\u001b[24;0f\u001b[42m\u001b[30m进度：[  0%]\u001b[49m\u001b[39m [..............................................................] \u001b8\u001b7\u001b[24;0f\u001b[42m\u001b[30m进度：[ 20%]\u001b[49m\u001b[39m [############..................................................] \u001b8正在解压 ngrok (3.16.0) ...\n",
      "\u001b7\u001b[24;0f\u001b[42m\u001b[30m进度：[ 40%]\u001b[49m\u001b[39m [########################......................................] \u001b8正在设置 ngrok (3.16.0) ...\n",
      "\u001b7\u001b[24;0f\u001b[42m\u001b[30m进度：[ 60%]\u001b[49m\u001b[39m [#####################################.........................] \u001b8\u001b7\u001b[24;0f\u001b[42m\u001b[30m进度：[ 80%]\u001b[49m\u001b[39m [#################################################.............] \u001b8\n",
      "\u001b7\u001b[0;24r\u001b8\u001b[1A\u001b[J"
     ]
    }
   ],
   "source": [
    "!curl -sSL https://ngrok-agent.s3.amazonaws.com/ngrok.asc \\\n",
    "\t| sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null \\\n",
    "\t&& echo \"deb https://ngrok-agent.s3.amazonaws.com buster main\" \\\n",
    "\t| sudo tee /etc/apt/sources.list.d/ngrok.list \\\n",
    "\t&& sudo apt update \\\n",
    "\t&& sudo apt install ngrok"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e05ca73b-25d9-439f-b9bd-5518c60f0a33",
   "metadata": {
    "ExecutionIndicator": {
     "show": true
    },
    "execution": {
     "iopub.execute_input": "2024-09-25T01:20:39.668319Z",
     "iopub.status.busy": "2024-09-25T01:20:39.667946Z",
     "iopub.status.idle": "2024-09-25T01:20:39.893681Z",
     "shell.execute_reply": "2024-09-25T01:20:39.893059Z",
     "shell.execute_reply.started": "2024-09-25T01:20:39.668298Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Authtoken saved to configuration file: /root/.config/ngrok/ngrok.yml\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  0%|\u001b[34m          \u001b[0m| 0/2 [00:00<?, ?it/s]\n",
      "  0%|\u001b[34m          \u001b[0m| 0/2 [00:00<?, ?it/s]\u001b[A"
     ]
    }
   ],
   "source": [
    "!ngrok config add-authtoken 2OGaG1dlCOclVmhQqUoov4hL0xT_31UoeUfdJc3YH5btC9aLZ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "f4c52a85-fb0f-4ed5-ace7-c21438b2069e",
   "metadata": {
    "ExecutionIndicator": {
     "show": false
    },
    "execution": {
     "iopub.execute_input": "2024-09-24T08:57:05.362445Z",
     "iopub.status.busy": "2024-09-24T08:57:05.362113Z",
     "iopub.status.idle": "2024-09-24T08:57:05.365041Z",
     "shell.execute_reply": "2024-09-24T08:57:05.364583Z",
     "shell.execute_reply.started": "2024-09-24T08:57:05.362424Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# !nohup ngrok http 8800 &"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
